package com.zqwh.xtool.model.offline;

import android.content.Context;

import com.zqwh.yj.sdk.utils.httpRequest.subscribers.NetCallback;
import com.zqwh.xtool.api.offline.DeviceResposity;
import com.zqwh.xtool.domain.DeviceConfigVO;
import com.zqwh.xtool.greendao.db.Device;
import com.zqwh.xtool.model.DeviceModel;

import java.util.List;

public class DeviceModelOfflineImpl implements DeviceModel {
    private Context context;
    private DeviceResposity deviceResposity;

    public DeviceModelOfflineImpl(Context context) {
        this.context = context;
        this.deviceResposity = new DeviceResposity(this.context);
    }

    @Override
    public void activated(String sn, NetCallback<DeviceConfigVO> callback) {
        Device device = deviceResposity.queryDeviceBySn(sn);
        DeviceConfigVO deviceConfigVO = new DeviceConfigVO();
        deviceConfigVO.setDevId(device.getDevId());
        deviceConfigVO.setRfidAntNumber(device.getRfidAntNumber());
        deviceConfigVO.setRfidInventoryDuration(device.getRfidInventoryDuration());
        deviceConfigVO.setRfidPower(device.getRfidPower());
        deviceConfigVO.setRfidType(device.getRfidType());
        deviceConfigVO.setRfidUartPath(device.getRfidUartPath());

        if (device == null){
            callback.onError("该设备未激活");
        }else {
            callback.onSuccess(deviceConfigVO);
        }
    }

    @Override
    public boolean insertDevice(Device device) {
        return deviceResposity.insertDevice(device);
    }

    @Override
    public boolean insertMultDevice(List<Device> deviceList) {
        return deviceResposity.insertMultDevice(deviceList);
    }
}
